# -*- coding: utf-8 -*-#
#-------------------------------------------------------------------------------
# 建立者:        黄周云  
# Name:         test07
# Description:   例9.7
# Author:       ASUS
# Date:         2019/3/12
#-------------------------------------------------------------------------------


# 未抛出异常时执行finally子句中的代码
def fun1():
    try:
        print("fun1 正常执行")
    finally:
        print("fun1 finally")
# 抛出异常时执行finally子句中的代码
def fun2():
    try:
        raise Exception
    except:
        print("fun2 抛出异常")
    finally:
        print("fun2 finally")
# 用return语句退出函数之前执行finally子句中的代码
def fun3():
    try:
        return 20
    finally:
        print("fun3 finally")
# 在finally子句中，尽可能的避免执行易抛出异常的语句，如果非要执行这类语句，建议再次加上try语句
def fun4():
    try:
        x = 1/0
    except ZeroDivisionError as e:
        print(e)
    finally:
        print("fun4 finally")
        try:
            del x
        except Exception as e:
            print(e)


fun1()
fun2()
print(fun3())
fun4()
